import React, {Component} from 'react';
import HeaderSelect from '../../components/header-select/header-select'
import Register from "../register/register";
import {connect} from 'react-redux'
import { update} from '../../redux/actions'
import {NavBar,InputItem,TextareaItem,Button} from 'antd-mobile'

class AdminInfo extends Component {
    state = {
        userid : this.props.user._id,
        header: '', // 头像名称
        info: '', // 职位简介
        post: '', // 职位名称
        company: '', // 公司名称
        salary: '' // 工资
    }
    setHeader =(header) =>{
        this.setState({header});
    }
    handleChange = (text,val) => {
        this.setState({
            [text]:val
        });
    }

    render() {
        const  {user} = this.props
        if(user.header){
            return <Register to='/admin' />
        }
        return (
            <div>
                <NavBar>管理员信息完善</NavBar>
                <HeaderSelect setHeader={this.setHeader}></HeaderSelect>
                <InputItem onChange={(val) => {this.handleChange('post',val)}}>职位</InputItem>
                <InputItem onChange={(val) => {this.handleChange('company',val)}}>公司名称</InputItem>
                <InputItem onChange={(val) => {this.handleChange('salary',val)}}>级别</InputItem>
                <TextareaItem  onChange={(val) => {this.handleChange('info',val)}} rows={3} title="介绍:"> </TextareaItem>
                <Button type='primary' onClick={ () => this.props.update(this.state)}>保存</Button>
            </div>
        );
    }
}

export default connect(
    state => ({user:state.user}),
    {update}
)(AdminInfo);